package com.flida.echart.core.utils;

import com.flida.bana.common.util.DateUtils;
import com.flida.bana.common.util.GeoHash;
import com.flida.echart.core.api.order.entity.Order;
import org.apache.commons.lang3.Validate;
import org.springframework.beans.factory.annotation.Value;

/**
 * Created by yzc on 2016/12/14.
 */
public class RedisKeyUtils {

    @Value("${order.rediskey}")
    public static String orderRediskey;

    @Value("${date.formate1}")
    public static String dateFormate;



    public static  String getOrderKey(Order order){
        StringBuffer orderKey=new StringBuffer();
        if(null!=order){
            orderKey.append(orderRediskey+order.getCityid());
        }
        return orderKey.toString();
    }


    /**
     * 通过经纬度 获取geohash值
     *
     * @param latitude 经度
     * @param longitude 纬度
     * @return
     */
    public static  String getGeoHashKey(Double latitude,Double longitude){

        Validate.notNull(latitude, "latitude [destination bean] not null!", new Object[0]);
        Validate.notNull(longitude, "longitude [destination bean] not null!", new Object[0]);
        return new GeoHash(latitude,longitude).getGeoHashBase32();

    }

    public static  String getOrderKey(int cityid){
        StringBuffer orderKey=new StringBuffer();
        if(cityid>0){
            orderKey.append(orderRediskey+cityid);
        }
        return orderKey.toString();
    }


    public static  Long getOrderScore(){

       return DateUtils.getTickTime(DateUtils.getNoTime(dateFormate),dateFormate);

    }

}
